package com.sgai.dcac.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.sgai.dcac.AppApplication;
import com.sgai.dcac.data.entity.UserInfo;

/**
 * Created by tony on 2017/6/20.
 */

public class UserUtil {
    private static String CURRENT_USERNAME = "current_username";
    public static String USERNAME = "username";
    public static String PASSWORD = "password";
    public static String TOKEN = "token";
    public static String JURISDICTION = "jurisdiction";
    public static SharedPreferences sp;
    static {
        sp = AppApplication.getInstance().getSharedPreferences(CURRENT_USERNAME, Context.MODE_PRIVATE);
    }

    public static UserInfo getCurrentUserInfo () {
        UserInfo userInfo = new UserInfo();
        userInfo.setUsername(sp.getString(USERNAME,""));
        userInfo.setUsername(sp.getString(PASSWORD,""));
        userInfo.setUsername(sp.getString(TOKEN,""));
        userInfo.setUsername(sp.getString(JURISDICTION,""));
        return userInfo;
    }

    public static boolean setCurrentUserInfo (UserInfo userInfo) {
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(USERNAME,userInfo.getUsername());
        editor.putString(PASSWORD,userInfo.getUsername());
        editor.putString(TOKEN,userInfo.getUsername());
        editor.putString(JURISDICTION,userInfo.getJurisdiction());
        return editor.commit();
    }

    public static String getCurrentUsername() {
        return sp.getString(USERNAME,"");
    }

    public static boolean setCurrentUsername(String currentUsername) {
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(USERNAME,currentUsername);
        return editor.commit();
    }

    public static String getCurrentPassword() {
        return sp.getString(PASSWORD,"");
    }

    public static boolean setCurrentPassword(String currentPassword) {
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(PASSWORD,currentPassword);
        return editor.commit();
    }

    public static String getCurrentToken() {
        return sp.getString(TOKEN,"");
    }

    public static boolean setCurrentToken(String currentToken) {
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(TOKEN,currentToken);
        return editor.commit();
    }

    public static String getCurrentJurisdiction() {
        return sp.getString(JURISDICTION,"");
    }

    public static boolean setCurrentJurisdiction(String currentJurisdiction) {
        SharedPreferences.Editor editor = sp.edit();
        editor.putString(JURISDICTION,currentJurisdiction);
        return editor.commit();
    }
}
